#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define MAXN 5005
using namespace std;
int T, N;
typedef pair<int, int> rect;
rect sticks[MAXN];
int dp[MAXN];
int cnt;
void solve();
/**
 * DilWorth定理
 */
int main() {
    cin >> T;
    while (T--) {
        cin >> N;
        int a, b;
        for (int i = 0; i < N; i++) {
            cin >> a >> b;
            sticks[i] = make_pair(a, b);
        }
        solve();
        memset(dp, 0, sizeof dp);
    }
}

// void solve() {
//     sort(sticks, sticks + N);
//     int res = 0;
//     for (int i = 0; i < N; i++) {
//         dp[i] = 1;
//         for (int j = 0; j < i; j++) {
//             if (sticks[i].second < sticks[j].second)
//                 dp[i] = max(dp[i], dp[j] + 1);
//         }
//         res = max(dp[i], res);
//     }
//     cout << res << endl;
// }

void solve() {
    sort(sticks, sticks + N);
    cnt = 0;
    for (int i = 0; i < N; i++) {
        bool flag = true;
        for (int j = 0; j < cnt; j++) {
            if (sticks[i].second >= dp[j]) {
                dp[j] = sticks[i].second;
                flag = false;
                break;
            }
        }
        if (flag) dp[cnt++] = sticks[i].second;
    }
    cout << cnt << endl;
}